package com.ym.pms.getCoding;

import lombok.Data;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

@Component
@Data
public class NewCoding {

    String Number;
    SimpleDateFormat f = new SimpleDateFormat("yyyyMMddHHmmss");
    String data = f.format(new Date(System.currentTimeMillis()));

    public String getCoding(String prefix){
        Random random = new Random();
        String No = String.valueOf(random.nextInt(10000));
        for (int i = 0; i < 4; i++){
            No = No.length() < 4 ? "0" + No : No;
        }
        if(prefix.length()>2){
            prefix = prefix.substring(0,2);
        }
        Number = prefix+data+No;
        return Number;
    }
    public String getCoding(String prefix,Integer no){
        no = no % 10000;
        String No = String.valueOf(no);

        for (int i = 0; i < 4; i++){
            No = No.length() < 4 ? "0" + No : No;
        }
        if(prefix.length()>2){
            prefix = prefix.substring(0,2);
        }
        Number = prefix+data+No;

        return Number;
    }
}
